<template>
  <div class="relative w-full h-full">
    <PageHeader :title="$t('articleManage.文章管理')" />
    <!-- <div class="flex_aic_jcsb">
      <el-input
        v-model="account"
        placeholder="请输入文章标题"
        style="width: 256px"
      >
        <template #prefix>
          <span class="color-555555">文章标题</span>
        </template>
      </el-input>
      <div class="flex_aic">
        <el-button>重置</el-button>
        <el-button type="primary">查询</el-button>
      </div>
    </div> -->
    <!-- <div class="mt12 toolbar flex_aic_jcsb">
      <div class="addBtn flex_aic_jcc" @click="handleAdd">
        <SvgIcon name="iconxinzeng" class="mr8" />
        <span>新增文章</span>
      </div>
    </div> -->
    <el-table
      :data="tableData"
      style="width: 100%"
      class="cover-table mt12"
      border
      v-loading="loading"
    >
      <el-table-column :prop="'title' + locale" :label="$t('articleManage.文章标题')" />
      <!-- <el-table-column prop="create_time" label="创建时间" /> -->
      <el-table-column :label="$t('articleManage.操作')">
        <template #default="scope">
          <div class="operationBtnRow">
            <el-button type="text" size="small" @click="handleWatch(scope.row)"
              >{{ $t('articleManage.查看') }}</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleEdit(scope.row)"
              v-my-point="'article:edit'"
              >{{ $t('articleManage.编辑') }}</el-button
            >
            <!-- <el-popconfirm
              title="确定删除吗？"
              @confirm="handleDelete(scope.row)"
              confirm-button-text="确定"
              cancel-button-text="取消"
              width="260px"
            >
              <template #reference>
                <el-button class="ml0" type="text" size="small">删除</el-button>
              </template>
            </el-popconfirm> -->
          </div>
        </template>
      </el-table-column>
    </el-table>

    <div class="flex justify-end mt24 absolute bottom-0 right-0">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 20, 30, 40]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
    <WatchDia v-model="showWatchDialog" :data="showWatchDialogData" />
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import Api from "@/config/api/api";
import { useI18n } from "vue-i18n";
import WatchDia from "./watchDia.vue";

const { locale, t } = useI18n();
const router = useRouter();
const account = ref("");
const currentPage = ref(1);
const pageSize = ref(10);
const tableData = ref([]);
const loading = ref(true);
const total = ref(0);
const showWatchDialog = ref(false);
const showWatchDialogData = ref({});
const handleDelete = (row) => {
  console.log(row);
};
const handleEdit = (row) => {
  router.push({
    path: "/manage_product/articleManage/edit",
    query: {
      code: row.code,
    },
  });
};
const handleSizeChange = (size) => {
  pageSize.value = size;
};
const handleCurrentChange = (page) => {
  currentPage.value = page;
};
const handleAdd = () => {
  router.push("/manage_product/articleManage/edit");
};
const getArticleList = () => {
  loading.value = true;
  Api.articleList({
    page: currentPage.value - 1,
    size: pageSize.value,
  })
    .then((res) => {
      tableData.value = res.data?.content || [];
      total.value = Number(res.data?.totalElements || 0);
    })
    .finally(() => {
      loading.value = false;
    });
};

const handleWatch = (row) => {
  showWatchDialog.value = true;
  showWatchDialogData.value = row;
};

onMounted(() => {
  getArticleList();
});
</script>

<style lang="scss" scoped>
.addBtn {
  height: 28px;
  margin-left: 10px;
  padding: 0 7px;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
}
.split {
  width: 1px;
  height: 12px;
  background: #ddd;
  margin: 0 5px;
}
</style>
